package com.jxt.myjxtmanager.views;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.WindowManager;
import android.widget.TextView;

import com.jxt.myjxtmanager.R;

/**
 * loading 框...
 */
public class CustomProgressDialog extends ProgressDialog {

    private String str;
    private TextView tvMsg;

    public CustomProgressDialog(Context context, String strMessage) {
        this(context, R.style.CustomProgressDialog, strMessage);
    }

    public CustomProgressDialog(Context context, int theme, String strMessage) {
        super(context, theme);
        str = strMessage;

    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_custom_progressdialog);
        WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
        layoutParams.gravity = Gravity.CENTER;
        layoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
        layoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
        layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
//		getWindow().getAttributes().gravity = Gravity.CENTER;
        tvMsg = (TextView) this.findViewById(R.id.id_tv_loadingmsg);
        tvMsg.setText(str);
//		 // 添加动画
//        Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation( 
//                context, R.anim.load_animation);  
//        spaceshipImage.startAnimation(hyperspaceJumpAnimation);
    }

    public void showDialog() {
        show();
        setCanceledOnTouchOutside(false);
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        if (!hasFocus) {
            dismiss();
        }
    }

}